package com.itany.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itany.dao.ArticleDao;
import com.itany.entity.Article;
import com.itany.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Author:yaozhiyuan0117@163.com
 * Time:2019/12/21 9:51
 * Describe:
 * version:1.0
 */
@Service
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class ArticleServiceImpl implements ArticleService {


    @Autowired
    ArticleDao articleDao;

    // @Override
    // public PageInfo findByPage(Integer page, Integer rows) {
    //
    //     PageHelper.startPage(page, rows);
    //     List<Article> articles = articleDao.selectByPage();
    //     PageInfo<Article> articlePageInfo = new PageInfo<>(articles);
    //     return articlePageInfo;
    //
    // }

    @Override
    public PageInfo findByPage(Integer page, Integer rows, String title, String type, String mode) {

        PageHelper.startPage(page, rows);
        Map map = new HashMap<>();
        map.put("title", title);
        map.put("type",type);
        map.put("mode",mode);
        List<Article> articles = articleDao.selectByPage(map);
        PageInfo<Article> articlePageInfo = new PageInfo<>(articles);
        return articlePageInfo;
    }

    @Override
    public List<Article> findAll() {
        return articleDao.selectByPage(new HashMap());
    }
}
